var e = require("../../utils/config.js");

Page({
    data: {
        workDay: "",
        goWorkTime: "",
        offWorkTime: "",
        restTime: "",
        remark: "",
        id: ""
    },
    onLoad: function(e) {
        var t = this;
        if (e.userTaskId) t.setData({
            userTaskId: e.userTaskId
        }); else if (e.obj) {
            console.log(e.obj);
            var a = JSON.parse(e.obj);
            t.setData({
                workDay: a.goWorkTime.split(" ")[0],
                remark: a.remark,
                goWorkTime: a.goWorkTime.split(" ")[1],
                offWorkTime: a.offWorkTime.split(" ")[1],
                id: a.id,
                restTime: a.restTime
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    bindChangeWorkDay: function(e) {
        this.setData({
            workDay: e.detail.value
        });
    },
    bindChangeGoWorkTime: function(e) {
        this.setData({
            goWorkTime: e.detail.value
        });
    },
    bindChangeOffWorkTime: function(e) {
        this.setData({
            offWorkTime: e.detail.value
        });
    },
    getRestTime: function(e) {
        this.setData({
            restTime: e.detail.value
        });
    },
    getRemark: function(e) {
        this.setData({
            remark: e.detail.value
        });
    },
    remove: function() {
        var t = this;
        wx.showModal({
            title: "系统提示",
            content: "是否确认删除？",
            success: function(a) {
                a.confirm && (wx.showLoading({
                    mark: !0
                }), wx.request({
                    url: e.urlList.API_RECORD_WORK_TIME_REMOVE,
                    method: "POST",
                    data: {
                        userId: wx.getStorageSync("userId"),
                        id: t.data.id
                    },
                    success: function(e) {
                        wx.hideLoading(), 200 == e.data.status ? wx.navigateBack({
                            success: function() {
                                wx.showToast({
                                    title: "删除成功"
                                });
                            }
                        }) : wx.showToast({
                            icon: "none",
                            title: e.data.message
                        });
                    }
                }));
            }
        });
    },
    save: function() {
        var t = this;
        t.data.workDay ? t.data.goWorkTime ? t.data.offWorkTime ? (wx.showLoading({
            mark: !0
        }), wx.request({
            url: t.data.id ? e.urlList.API_RECORD_WORK_TIME_UPDATE : e.urlList.API_RECORD_WORK_TIME_ADD,
            method: "POST",
            data: {
                serviceProviderId: wx.getStorageSync("serviceProviderId"),
                userId: wx.getStorageSync("userId"),
                goWorkTime: t.data.workDay + " " + t.data.goWorkTime,
                offWorkTime: t.data.workDay + " " + t.data.offWorkTime,
                restTime: t.data.restTime ? t.data.restTime : 0,
                remark: t.data.remark,
                id: t.data.id
            },
            success: function(e) {
                wx.hideLoading(), 200 == e.data.status ? wx.navigateBack({
                    success: function() {
                        wx.showToast({
                            title: "提交成功"
                        });
                    }
                }) : 416 == e.data.status ? wx.showModal({
                    title: "系统提示",
                    content: e.data.message,
                    cancelText: "下次再说",
                    confirmText: "实名认证",
                    success: function(e) {
                        e.confirm && wx.navigateTo({
                            url: "/pages/my/realNameAuthentication"
                        });
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.data.message
                });
            }
        })) : wx.showToast({
            title: "请选择下班时间",
            icon: "none"
        }) : wx.showToast({
            title: "请选择上班时间",
            icon: "none"
        }) : wx.showToast({
            title: "请选择上班日期",
            icon: "none"
        });
    }
});